import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import "bootstrap";
import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
import axios from "axios";
import {
  ValidationProvider,
  localize,
  extend,
  configure
} from "vee-validate/dist/vee-validate.full.esm";
import zh_CN from "vee-validate/dist/locale/zh_CN.json";
import { validate } from "vee-validate";

localize("zh_CN", zh_CN);

configure({
  classes: {
    valid: "is-valid",
    invalid: "is-invalid",
    dirty: ["is-dirty", "is-dirty"] // multiple classes per flag!
    // ...
  }
});

//自定义验证
extend("enum", {
  validate: value => {
    return value !== -1;
  },
  message: "请选择正确的类型"
});

Vue.component("ValidationProvider", ValidationProvider);

Vue.config.productionTip = false;

new Vue({
  router,
  render: h => h(App)
}).$mount("#app");

axios.interceptors.request.use(
  config => {
    if (sessionStorage.token) {
      // 判断是否存在Bearer，如果存在的话，则每个http header都加上Bearer
      config.headers.Authorization = `Bearer ${sessionStorage.token}`;
    }
    return config;
  },
  err => {
    return Promise.reject(err);
  }
);
